package cn.iocoder.yudao.module.erp.dal.mysql.purchaseplan.purchaseminordetail;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.purchaseplan.vo.purchaseminordetail.PurchaseMinorDetailPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchaseplan.purchaseminordetail.PurchaseMinorDetailDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 小额采购计划明细 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PurchaseMinorDetailMapper extends BaseMapperX<PurchaseMinorDetailDO> {

    default PageResult<PurchaseMinorDetailDO> selectPage(PurchaseMinorDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PurchaseMinorDetailDO>()
                .eqIfPresent(PurchaseMinorDetailDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(PurchaseMinorDetailDO::getPurchaseType, reqVO.getPurchaseType())
                .likeIfPresent(PurchaseMinorDetailDO::getItemName, reqVO.getItemName())
                .eqIfPresent(PurchaseMinorDetailDO::getUnit, reqVO.getUnit())
                .eqIfPresent(PurchaseMinorDetailDO::getSpecModel, reqVO.getSpecModel())
                .eqIfPresent(PurchaseMinorDetailDO::getAcceptanceStandard, reqVO.getAcceptanceStandard())
                .eqIfPresent(PurchaseMinorDetailDO::getOriginPlace, reqVO.getOriginPlace())
                .eqIfPresent(PurchaseMinorDetailDO::getEstimatedQuantity, reqVO.getEstimatedQuantity())
                .eqIfPresent(PurchaseMinorDetailDO::getEstimatedUnitPrice, reqVO.getEstimatedUnitPrice())
                .eqIfPresent(PurchaseMinorDetailDO::getTotalAmount, reqVO.getTotalAmount())
                .eqIfPresent(PurchaseMinorDetailDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(PurchaseMinorDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PurchaseMinorDetailDO::getId));
    }

    default void deleteByPlanId(Long planId){
        LambdaUpdateWrapper<PurchaseMinorDetailDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(PurchaseMinorDetailDO::getPlanId, planId);
        this.delete(updateWrapper);
    }

    default List<PurchaseMinorDetailDO> selectByPlanId(Long planId){
        LambdaQueryWrapper<PurchaseMinorDetailDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PurchaseMinorDetailDO::getPlanId, planId)
                .eq(PurchaseMinorDetailDO::getDeleted,0);
        return this.selectList(queryWrapper);
    }
}